<?php 


require "../common/Curl.php";

/**
 *	https://open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fsgv49u&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	静默签署授权API----接口顺序排列封装
 *  使用请求签名鉴权方式
 *  下一个------------------ 印章服务seal.php
 */


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [setsignAuth 根据个人/机构签署账号ID设置静默签署授权]    有用    
 * 签署用户（个人/企业）如果需要自动盖章签署时，需要先通过该接口完成静默签署授权。
 * @param  [type] $accountId [个人/机构签署账号ID，通过创建个人/机构签署账号接口获取]
 * @param  [type] $deadline  [授权截止时间, 格式为yyyy-MM-dd HH:mm:ss，默认无限期]
 * @param  [type] $header    [请求头]
 * @param  string $url       [请求地址]
 * @return [json]            [返回成功]
 */
function setsignAuth($accountId,$deadline,$appId,$secret,$url){
	$urlss = $url."/v1/signAuth/".$accountId;
	$head_url = "/v1/signAuth/".$accountId;
	$data = [
		'accountId'=>$accountId,
		"deadline"=>$deadline
	];
	
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $accountId = "5539bd029e4e45f4b2095aacbcf1ea19";
// $deadline = '2021-09-26 11:00:00';
// $a = setsignAuth($accountId,$deadline,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [deletesignAuth 根据个人/机构签署账号ID解除静默签署授权]   这里为什么要用curlData这个https请求，搞不懂
 * @param  [type] $accountId [个人/机构签署账号ID，通过创建个人/机构签署账号接口获取]
 * @param  [type] $header    [请求头]
 * @param  string $url       [请求地址]
 * @return [json]            [返回成功]
 */
function deletesignAuth($accountId,$appId,$secret,$url){
	$urlss = $url."/v1/signAuth/".$accountId;
	$head_url = "/v1/signAuth/".$accountId;
	$data = [];
	
    $res = json_encode($data);
    $header = getHeader($data,"DELETE",$head_url,$appId,$secret,$url);
    // $result = sendHttp($method="DELETE",$urlss,$header,$res);
    $result = curlData($urlss, $data='', $header, $method = 'DELETE', $type='json');
    return $result;
}
// $accountId = "f120cf3f2a124fc88f8438d6c919b8b6";
// $a = deletesignAuth($accountId,$appId,$secret,$url);
// var_dump($a);die;



